package com.bruce.asurada.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.bruce.asurada.store.MongoChatMemotyStore;

import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import jakarta.annotation.Resource;

@Configuration
public class AssistantConfig {

    @Resource
    private MongoChatMemotyStore chatMemoryStore;
    
    @Bean
    public StreamingChatLanguageModel streamingChatModel(OpenAiStreamingChatModel openAiStreamingChatModel) {
        return openAiStreamingChatModel;
    }

    @Bean
    public ChatMemoryProvider chatMemoryProvider(){
        return memoryId -> MessageWindowChatMemory
                     .builder()
                     .id(String.valueOf(memoryId))
                     .maxMessages(20)
                     .chatMemoryStore(chatMemoryStore)
                     .build();
    }

}
